/*
 * Copyright 2011 OpenWAF.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.openwaf.client.dom;

import com.openwaf.client.core.Client;

import com.openwaf.common.annotation.NoJavaScript;

public class NativeEvent  {

    public static final int BUTTON_LEFT = 1;
    public static final int BUTTON_RIGHT = 2;
    public static final int BUTTON_MIDDLE = 4;

    protected NativeEvent() {
    }
    //TODO:define this

    public final native String getType()/*- {
         return this.type;
    } -*/;
    //TODO:define this

    public final native boolean getAltKey()/*- {
         return this.altKey;
    } -*/;

    //TODO:define this
    public final native boolean getCtrlKey()/*- {
        return this.ctrlKey;
     } -*/;

    //TODO:define this
    public final native boolean getShiftKey()/*- {
        return this.shiftKey;
     } -*/;

    //TODO:define this
    public final native int getButton()/*- {
        return this.button;
     } -*/;

    //TODO:define this
    public final native int getCharCode()/*- {
        return -1;
     } -*/;

    //TODO:define this
    public final native int getClientX()/*- {
        return this.clientX;
     } -*/;

    //TODO:define this
    public final native int getClientY()/*- {
        return this.clientY;
     } -*/;

    //TODO:define this
    public final native int getKeyCode()/*- {
        return this.keyCode;
     } -*/;


    //TODO:define this
    public final native boolean getMetaKey()/*- {
        return this.metaKey;
    } -*/;

    //TODO:define this
    public final native int getScreenX()/*- {
        return parseInt(this.screenX);
    } -*/;

    //TODO:define this
    public final native int getScreenY()/*- {
        return parseInt(this.screenY);
    } -*/;

    //TODO:check this
    public final native Element getTarget()/*- {
      if(this.target)
         return this.target;
      if(this.srcElement)
         return this.srcElement;
      return null;
    }-*/;
    @NoJavaScript //placeholder to protect native javascript method
    private native void preventDefault(int a);
    @NoJavaScript //placeholder to protect native javascript method
    private native void stopPropagation(int a);
    
    //TODO:define this
    public final void preventDefault(){
        if(Client.IE && !(Client.IE_9_OR_ABOVE)){
            this.preventDefault_IE_Legacy();
        }else{
            this.preventDefault(0);
        }
    }
    private native void preventDefault_IE_Legacy()/*-{
         this.returnValue=false;
    }-*/;
    //TODO:define this
    public final void stopPropagation(){
        if(Client.IE && !(Client.IE_9_OR_ABOVE)){
            this.stopPropogation_IE_Legacy();
        }else{
            this.stopPropagation(0);
        }
     }
    private native void stopPropogation_IE_Legacy()/*-{
         this.cancelBubble=false;
    }-*/;

}
